<template>
<div class='page'>
  <div class='nav'>
    <div class="input_view flex_ac" @click="$back() ">
      <van-icon class="ml6" name="arrow-left" size="26" color="#000"/>
      <div class="nav_title">乡贤</div>
      <img class="mla mr10" width="22px" height="22px" src="~@/assets/img/xiangxian/search.png" alt="">
    </div>
    <div class="h15"></div>
    <Shaixuan :isCity="true" :isChain="true" @changeInit="changeInit" />
    <div class="h15"></div>
	</div>
  <div class="h100"></div>
  <div class="total mb10">为您找到 <span style="color: #FA8A26;">{{ total }}</span> 个乡贤</div>
  <div class="box_div"  ref="gun">
    <van-list
      v-model="isLoad"
      :finished="isfinish"
      finished-text="没有更多了"
      @load="getMore"
    > 
      <div class="flex_w flex_sb">
        <div class="box_item" v-for="i,k in list" :key="k" @click="toDetail(i.id)">
          <div class="box_img">
            <img :src="i.imgs" />
          </div>
          <div class="box_name">{{ i.name }}</div>
          <div class="box_desc">{{ i.company_infos[0].career }}</div>
        </div>
        <div class="box_item"></div>
      </div>
    </van-list>
  </div>
</div>
</template>
<script>
import Shaixuan from '@/components/Shaixuan.vue'
import {xiangxian} from '@/api/api.js'
export default {
  components: {
    Shaixuan
  },
  data() {
    return {
      total: 0,
      page: 1,
      isfinish: false,
      isLoad: true,
      list:[]
    }
  },
  created() {
    this.init()
  },
  methods: {
    changeInit(query) {
      this.query = query
      this.init()
    },
    init() {
      this.page = 1
      this.isfinish = false
      this.isLoad = true
      this.list = []
      this.getList()
    },
    getMore() {
      if (this.isfinish||this.list.length==0) {
        return
      }
      this.page++
      this.getList()
    },
    getList() {
      let data = {
        page: this.page,
        ...this.query
      }
      xiangxian.getList({...data}).then(res => {
        this.isLoad = false
        this.list.push(...res.data.data)
        this.total = res.data.total
        if (this.list.length >= this.total) {
          this.isfinish = true
        }
      })
    },
    toDetail(id) {
      this.$router.push({name: 'xiangxianDetail', query: {id}})
    }
  }
}
</script>
<style lang="scss" scoped>
.nav{
	width: 100%;
	position: fixed;
	top: 0;
	left: 0;
	background-color: rgba($color: #fff, $alpha: 1);
	z-index: 10;
	transition: all 0.5s;
}
.input_view{
	width: 100%;
  height: 40px;
	.nav_title{
		font-weight: 500;
		font-size: 18px;
		color: #000;
	}
}

.page{
	height:100%;
	width:100%;
	background: #F4F4F4;;
  .total{
    margin-left: 10px;
    font-size: 10px;
    color: #333333;
  }
}
.box_div{
  margin: 0 10px 10px;
  padding: 10px;
  background: #FFFFFF;
  box-shadow: 0px 3px 9px 2px rgba(250,135,30,0.13);
  border-radius: 4px 4px 4px 4px;
  height: calc(100% - 150px);
  overflow: auto;
  .box_item{
    width: 100px;
    padding-bottom: 10px;
    .box_img{
      width: 100px;
      height: 100px;
      position: relative;
      img{
        width: 100%;
        height: 100%;
        border-radius: 3px;
      }
      .box_add{
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        background: #0008;
        border-radius: 0 0 3px 3px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        font-size: 12px;
        color: #FFFFFF;
      }
    }
    .box_name{
      margin-top: 5px;
      text-align: center;
      font-size: 14px;
      color: #000000;
      line-height: 20px;
    }
    .box_desc{
      font-size: 11px;
      color: #808080;
      line-height: 17px;
      text-align: center;
      margin-top: 5px;
    }
  }
}
</style>